using System;
using System.Collections;

namespace WoWAddonRefresh.Entities {
	/// <summary>
	/// Summary description for Addon.
	/// </summary>
	public class Toc {
		public string Name;
		public string Folder;
		public string FullName;
		public DateTime LocalTocDate;
		public Guid ID;
	}

	public class TocCollection : CollectionBase {
		public TocCollection() {}

		/// <summary>
		/// Adds a Toc to the collection.
		/// </summary>
		/// <param name="newToc">new Toc</param>
		public int Add(Toc newToc) {
			return List.Add(newToc);
		}

        public bool Exist(Toc item) {
            foreach(Toc toc in this.InnerList) {
                if (toc.FullName == item.FullName) {
                    return true;
                }
            }
            return false;
        }

        private Toc mainToc = null;
        public Toc MainToc {
            get {
                return mainToc;
            }
            set {
                mainToc = value;
            }
        }

		public void Remove(Toc toc){
			int index = -1;
			for (int i = 0; i < this.Count; i++) {
				if (this[i].ID == toc.ID) index = i;
			}
			if (index >= 0) this.RemoveAt(index);
		}

		/// <summary>
		/// Gets or sets the <see cref="Toc"/> at the specified index.
		/// In C#, this property is the indexer for the IList interface.
		/// </summary>
		public Toc this[int index] {
			get {
				return (Toc)List[index];
			}
			set {
				throw new System.NotSupportedException("Please use the Add() method."); 
			} 
		}	
	}
}
